﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using BizElements.Core.ProviderComponents;

namespace BizElements.Core
{
    /// <summary>
    /// List of columns in which to insert data and the list of data values to be inserted.
    /// </summary>
    [Serializable]
    public sealed class InsertList : IEnumerable, IEnumerable<InsertExpression>
    {
        #region Strong-typed collection.

        List<InsertExpression> list = new List<InsertExpression>();

        /// <summary>
        /// Creates a new InsertList.
        /// </summary>
        internal InsertList()
        { 
        }

        /// <summary>
        /// Gets total number of items in this collection.
        /// </summary>
        public int Count
        {
            get { return this.list.Count; }
        }

        /// <summary>
        /// Adds a column-value pair to the collection.
        /// </summary>
        /// <param name="column">Column.</param>
        /// <param name="value">Value that is inserted in the given column. May be <b>null</b>.</param>
        internal void Add(IDbColumn column, object value)
        {
            this.list.Add(new InsertExpression(column, value));
        }

        #endregion

        #region IEnumerable.

        /// <summary>
        /// Gets an enumerator that can iterate through InsertList.
        /// </summary>
        public IEnumerator GetEnumerator()
        {
            return this.list.GetEnumerator();
        }

        #endregion

        #region IEnumerable<InsertExpression> Members

        IEnumerator<InsertExpression> IEnumerable<InsertExpression>.GetEnumerator()
        {
            return this.list.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}